home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CD Exchange
/
CD Exchange - Volume 1.iso
/
utils
/
misc
/
bytefilter
/
source
/
bytefilter.s
next >
Wrap
Text File
|
1993-10-14
|
15KB
|
762 lines
;
; ByteFilter V1.20 05-Sep-1993
;
; (c) 1993 by Jan Hagqvist
;
; V0.01 Friday, 03-Sep-1993 ; Open window etc.
; V0.30 Saturday, 04-Sep-1993 ; Filter, slow mode
; V1.00 - " " - ; Filter, fast mode
; V1.05 Sunday, 05-Sep-1993 ; Fixed a bug in fast&slow-filter
; V1.20 - " " - ; Filter, ultrafast mode
include "jhextras.i"
XREF _LVOOpenLibrary
XREF _LVOCloseLibrary
XREF _LVOOpenWindow
XREF _LVOCloseWindow
XREF _LVOWaitPort
XREF _LVOGetMsg
XREF _LVOReplyMsg
XREF _LVOMove
XREF _LVOText
XREF _LVOActivateGadget
XREF _LVORefreshGList
XREF _LVORemoveGadget
XREF _LVOAddGadget
XREF _LVOSetAPen
XREF _LVOOpen
XREF _LVOClose
XREF _LVOSeek
XREF _LVORead
XREF _LVOWrite
XREF _LVOAllocMem
XREF _LVOFreeMem
JAM1 equ 0
WBENCHSCREEN equ 1
GFLG_GADGHCOMP equ $0000
GFLG_GADGHIMAGE equ $0002
GFLG_DISABLED equ $0100
GACT_RELVERIFY equ $0001
GACT_TOGGLESELECT equ $0100
GTYP_BOOLGADGET equ $0001
GTYP_STRGADGET equ $0004
IDCMP_GADGETUP equ $00000040
IDCMP_CLOSEWINDOW equ $00000200
WFLG_SMART_REFRESH equ $00000000
WFLG_DRAGBAR equ $00000002
WFLG_DEPTHGADGET equ $00000004
WFLG_CLOSEGADGET equ $00000008
WFLG_ACTIVATE equ $00001000
WFLG_RMBTRAP equ $00010000
ByteFilter
move.l 4,a6
moveq.l #0,d0
lea JHExtrasName(pc),a1
jsr _LVOOpenLibrary(a6)
move.l d0,JHExtrasBase
tst.l d0
beq Quit
move.l JHExtrasBase(pc),a0
move.l ml_DosLib(a0),DosBase
move.l ml_GfxLib(a0),GfxBase
move.l ml_IntuitionLib(a0),IntuitionBase
move.w ml_SysVersion(a0),SysVersion
bsr CreateHexGadgets
move.l IntuitionBase(pc),a6
lea NewWindow(pc),a0
jsr _LVOOpenWindow(a6)
move.l d0,MyWindow
move.l d0,a0
move.l 50(a0),MyRastPort
move.l 86(a0),MyUserPort
lea SourceNameGadget(pc),a0
bsr ActivateGadget
move.l GfxBase(pc),a6
move.l MyRastPort(pc),a1
moveq.l #2,d0
jsr _LVOSetAPen(a6)
move.l #GreetsString,StatusArgs
bsr ShowStatusLine
WaitForMessage
tst.b QuitFlag
bne Quit
move.l 4,a6
move.l MyUserPort(pc),a0
jsr _LVOWaitPort(a6)
WaitForMessage2
move.l 4,a6
move.l MyUserPort(pc),a0
jsr _LVOGetMsg(a6)
tst.l d0
beq.s WaitForMessage
move.l d0,a1
move.l 20(a1),Class
move.w 24(a1),Code
move.w 26(a1),Qualifier
move.l 28(a1),IAddress
jsr _LVOReplyMsg(a6)
cmp.l #IDCMP_CLOSEWINDOW,Class
bne.s WaitForMessage3
move.b #1,QuitFlag
WaitForMessage3
cmp.l #IDCMP_GADGETUP,Class
bne.s WaitForMessage4
move.l IAddress(pc),a0
tst.l 40(a0)
beq.s WaitForMessage4
move.l IntuitionBase(pc),a6
move.l 40(a0),a0
jsr (a0)
WaitForMessage4
bra WaitForMessage2
Quit
move.l IntuitionBase(pc),a6
tst.l MyWindow
beq.s Quit2
move.l MyWindow(pc),a0
jsr _LVOCloseWindow(a6)
Quit2
move.l 4,a6
tst.l JHExtrasBase
beq.s Quit3
move.l JHExtrasBase(pc),a1
jsr _LVOCloseLibrary(a6)
Quit3
moveq.l #0,d0
rts
ShowStatusLine
move.l GfxBase(pc),a6
move.l MyRastPort(pc),a1
move.l #374,d0
move.l #185,d1
jsr _LVOMove(a6)
move.l JHExtrasBase(pc),a6
lea StatusFormat(pc),a0
lea StatusArgs(pc),a1
lea StatusString,a2
jsr _LVOJHFormatAString(a6)
lea StatusString,a0
jsr _LVOJHStrLen(a6)
move.l GfxBase(pc),a6
move.l MyRastPort(pc),a1
jsr _LVOText(a6)
rts
Invert
move.l #InvertString,StatusArgs
bsr ShowStatusLine
move.l IntuitionBase(pc),a6
lea HexFlags,a3
lea HexGadgets,a4
lea IntuiTexts,a5
move.l #255,d3
Invert2
bchg #0,0(a3,d3.w)
bchg #7,13(a4)
add.l #44,a4
add.l #44,a5
dbf d3,Invert2
lea HexGadgets,a0
move.l MyWindow(pc),a1
sub.l a2,a2
moveq.l #-1,d0
jsr _LVORefreshGList(a6)
move.l #WaitingString,StatusArgs
bsr ShowStatusLine
rts
CheckHexFlag
lea HexFlags,a3
move.l IAddress,a4
move.w 38(a4),d3 ; Byte number
bchg #0,0(a3,d3.w) ; Change byte state
move.l #WaitingString,StatusArgs
bsr ShowStatusLine
rts
SourceName
lea DestNameGadget(pc),a0
bsr ActivateGadget
move.l #WaitingString,StatusArgs
bsr ShowStatusLine
rts
DestName
lea SourceNameGadget(pc),a0
bsr ActivateGadget
move.l #WaitingString,StatusArgs
bsr ShowStatusLine
rts
Filter
move.l DosBase(pc),a6
move.l #SourceFileName,d1
move.l #1005,d2
jsr _LVOOpen(a6)
move.l d0,d6 ; d6=sourcefile pointer
tst.l d0
beq NoSource
move.l JHExtrasBase(pc),a6
move.l #DestFileName,d1
move.l #1006,d2
move.l MyWindow(pc),a0
jsr _LVOJHOpen(a6)
move.l d0,d7 ; d7=destfile pointer
tst.l d0
beq NoDest
move.l DosBase(pc),a6
move.l d6,d1
moveq.l #0,d2
moveq.l #1,d3
jsr _LVOSeek(a6) ; Bounce to the end of the sourcefile
move.l d6,d1
moveq.l #0,d2
moveq.l #-1,d3
jsr _LVOSeek(a6) ; And back to the beginning
move.l d0,FileSize
move.l 4,a6
move.l FileSize(pc),d0
moveq.l #0,d1
jsr _LVOAllocMem(a6) ; Get mem for sourcefile
move.l d0,SourceMem
tst.l d0 ; Did we get the mem?
bne.s GetMem ; Yes
bsr FilterSlow ; No, do it slow
bra.s GetMem2
GetMem
move.l 4,a6
move.l FileSize(pc),d0
moveq.l #0,d1
jsr _LVOAllocMem(a6) ; Get mem for sourcefile
move.l d0,DestMem
tst.l d0 ; Did we get the mem?
beq.s GetMem1 ; No
bsr FilterUltraFast ; Do it ultrafast
bra.s GetMem2
GetMem1
bsr FilterFast ; Do it fast
GetMem2
move.l d0,d5 ; Store error flag
tst.l DestMem
beq.s GetMem3
move.l 4,a6
move.l DestMem(pc),a1
move.l FileSize(pc),d0
jsr _LVOFreeMem(a6) ; Free the mem
GetMem3
tst.l SourceMem
beq.s GetMem4
move.l 4,a6
move.l SourceMem(pc),a1
move.l FileSize(pc),d0
jsr _LVOFreeMem(a6) ; Free the mem
GetMem4
move.l DosBase(pc),a6
move.l d7,d1
jsr _LVOClose(a6) ; Close destfile
move.l d6,d1
jsr _LVOClose(a6) ; Close sourcefile
cmp.l #-1,d5 ; Was there a write error?
beq.s FilterWriteError
move.l #WaitingString,StatusArgs
bsr ShowStatusLine
rts
FilterWriteError
move.l #WriteErrorString,StatusArgs
bsr ShowStatusLine
rts
NoSource
move.l #NoSourceString,StatusArgs
bsr ShowStatusLine
rts
NoDest
move.l DosBase(pc),a6
move.l d6,d1
jsr _LVOClose(a6)
move.l #NoDestString,StatusArgs
bsr ShowStatusLine
rts
FilterUltraFast
move.l #FilteringUltraFastString,StatusArgs
bsr ShowStatusLine
move.l DosBase(pc),a6
move.l d6,d1
move.l SourceMem(pc),d2
move.l FileSize(pc),d3
jsr _LVORead(a6) ; Read the source file
cmp.l #-1,d0
beq.s FilterUltraFast2
move.l FileSize(pc),d4
move.l SourceMem(pc),a4
lea HexFlags,a5
move.l DestMem,a3
moveq.l #0,d5
FilterUltraFast3
move.b (a4)+,d0
ext.w d0
and.w #$00FF,d0
tst.b 0(a5,d0.w)
bne.s FilterUltraFast3.1
move.b d0,(a3)+ ; Store it to the buffer
addq.l #1,d5 ; Increase destfile length
FilterUltraFast3.1
subq.l #1,d4
tst.l d4
bne.s FilterUltraFast3
move.l d7,d1
move.l DestMem(pc),d2
move.l d5,d3
jsr _LVOWrite(a6) ; Write the destfile
FilterUltraFast2
rts
FilterFast
move.l #FilteringFastString,StatusArgs
bsr ShowStatusLine
move.l DosBase(pc),a6
move.l d6,d1
move.l SourceMem(pc),d2
move.l FileSize(pc),d3
jsr _LVORead(a6) ; Read the source file
cmp.l #-1,d0
beq.s FilterFast2
move.l FileSize(pc),d4
move.l SourceMem(pc),a4
lea HexFlags,a5
lea StatusString,a3
moveq.l #0,d5
FilterFast3
move.b (a4)+,d0
ext.w d0
and.w #$00FF,d0
tst.b 0(a5,d0.w)
bne.s FilterFast3.1
move.b d0,(a3)+ ; Store it to the buffer
addq.l #1,d5
cmp.w #256,d5 ; Buffer full?
bne.s FilterFast3.1 ; No
move.l d7,d1
move.l #StatusString,d2
move.l d5,d3
jsr _LVOWrite(a6) ; Write buffer
cmp.l #-1,d0 ; Error?
beq.s FilterFast2 ; Yes
lea StatusString,a3
moveq.l #0,d5
FilterFast3.1
subq